import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
// import parse from '@dfeidao/atom-nodejs/dt/parse';
import p001 from './p001';
import p002 from './p002';
import p003 from './p003';

import render from '@dfeidao/atom-web/render/render';
export default async function a003(fd: IFeidaoAiBrowserComponent) {
	// 这里是查询
    const pp =fd.data.node.querySelector<HTMLSelectElement>('[data-id="deptname"]');
	const department_no=pp.selectedOptions[0].value;
	const staff_name=fd.data.node.querySelector<HTMLInputElement>('[data-id="staff_name"]').value;
	const projectxm=fd.data.node.querySelector<HTMLSelectElement>('[data-id="projectxm"]');
	const project_no=projectxm.selectedOptions[0].value;
    const dd=fd.data.node.querySelector<HTMLSelectElement>('[data-id="post_name"]');
	const post_no=dd.selectedOptions[0].value;
	const rr=fd.data.node.querySelector<HTMLSelectElement>('[data-id="is_resident"]');
	const is_resident=rr.selectedOptions[0].value;
	const start=fd.data.node.querySelector<HTMLInputElement>('[data-id="starttime"]').value;
	const end=fd.data.node.querySelector<HTMLInputElement>('[data-id="endtime"]').value;
	let starttime;
	let endtime;
	if (start === '' && end === '') {
		const time = new Date();
		const year = time.getFullYear();
		const month=time.getMonth() + 1;
		let m;
		if (month < 10) {
			m = `0${month}`;
		}
		const date =time.getDate();
		endtime = `${year}-${m}-${date}`;
		endtime = new Date(endtime).getTime();
		starttime = new Date("1990-01-01").getTime();
	}
    if (start !== '' && end !== '') {
		starttime = new Date(start).getTime();
		endtime =  new Date(end).getTime();
	}
	if (start !== '' && end === '') {
		const time = new Date();
		const year = time.getFullYear();
		const month=time.getMonth() + 1;
		let m;
		if (month < 10) {
			m = `0${month}`;
		}
		const date =time.getDate();
		endtime = `${year}-${m}-${date}`;
		starttime = new Date(start).getTime();
		endtime = new Date(endtime).getTime();
	}
	if (start === '' && end !== '') {
		starttime = new Date("1990-01-01").getTime();
		endtime = new Date(end).getTime();
	}
	// tslint:disable-next-line:variable-name
	const DTp001 =fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
	// tslint:disable-next-line:variable-name
    const DTNp002=fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
     // tslint:disable-next-line:variable-name
    const DTFp003=fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');
	const ret = await nodejs<{dt: Array<{staff_no: string}>}>('staff-management/zj-000001/s010',{
			filter:{
				pn:1,
				department_no,
				project_no,
				post_no,
				staff_name,
				endtime,
				starttime,
		        is_resident
			}
	});
	if (ret.dt.length > 0) {
		    render(fd,ret.dt,p001,'p001','inner');
			DTNp002.style.display = "none";
		    DTp001.style.display = "block";
			DTFp003.style.display = "none";
				render(fd,ret.dt.length,p003,'p003','inner');
				DTFp003.style.display = "block";
	    } else {
		   render(fd,"",p002,'p002','inner');
		   DTNp002.style.display = "block";
		   DTp001.style.display = "none";
		   DTFp003.style.display = "none";
		}
		


























	// const renRender = ret.dt.map((item) => {
    //   return  Object.assign({},item,{project_no:"",project_name:"",is_resident:""} );
	// });
	// console.log("第一个表s10里面的数据",renRender);

	// if (ret.dt.length < 1) {
	// 	console.log("ret的长度",ret.dt.length);
	// 	console.log("chuc");
	// 	DTNp002.style.display = "block";
	// 	DTp001.style.display = "none";
	// 	DTFp003.style.display = "none";
	// 	render(fd,"",p002,'p002','inner');
	//     //return;
	// }else{
	// 	const ren = await nodejs<{dt: Array<{is_resident: string,project_no: string,project_name: string,pub_user_no: string}>}>('staff-management/zj-000001/s011',{filter:{
	// 		project_no,
	// 	    is_resident
	// 	}});
	// 	console.log("第二次拼接数据源",ren.dt);
    //     const render_dat=renRender.map((item) => {
	//     for (let i=0;i < ren.dt.length;i++) {
	//             if (item.staff_no === ren.dt[i].pub_user_no) {
	// 				console.log("拼接开始",item.staff_no,ren.dt[i].pub_user_no);
	// 		        item.project_no = ren.dt[i].project_no;
	// 		        item.project_name = ren.dt[i].project_name;
	// 				item.is_resident = ren.dt[i].is_resident;
	// 				// console.log("拼接后一条数据",item);
	// 			}
	// 		}
	// 		return item;	
	// 	});
    //  ///const Rdate= render_dat.filter((item) => item.is_resident !== "" );
	// 	 console.log("处理后的数据",render_dat); 
	// 	 ///console.log("Rdate处理后的数据",Rdate); 
	//     if (render_dat.length > 0) {
	// 	    render(fd,render_dat,p001,'p001','inner');
	// 		render(fd,ret.dt.length,p003,'p003','inner');
	// 		DTNp002.style.display = "none";
	// 	    DTp001.style.display = "block";
	// 	    DTFp003.style.display = "block";
	//     } else {
	// 	   render(fd,"",p002,'p002','inner');
	// 	   DTNp002.style.display = "block";
	// 	   DTp001.style.display = "none";
	// 	   DTFp003.style.display = "none";
	//     }

	// }

	// if (department_no === "" && staff_name === "" && project_no === "" && post_no === "" && is_resident === "" && start === "" && end === "") {
	// 	const ret = await nodejs<{dt: Array<{staff_no: string,project_no: string,project_name: string,is_resident: string}>,c: string}>('staff-management/zj-000001/s001',{filter:{pn:1}});
	//     const arr = Array();
	//     ret.dt.map((item) => {
	// 	   arr.push(item.staff_no);
	//     });
	//     const ren = await nodejs<{dt: Array<{is_resident: string,project_no: string,project_name: string,pub_user_no: string}>}>('staff-management/zj-000001/s002',{filter:{staff_no:arr}});
    //      const render_dat=ret.dt.map((item) =>{
	//      for (let i=0;i < ren.dt.length;i++) {
	//        if (item.staff_no === ren.dt[i].pub_user_no) {
	// 		  item.project_no = ren.dt[i].project_no;
	// 		  item.project_name = ren.dt[i].project_name;
	// 		  item.is_resident = ren.dt[i].is_resident;
	// 		  return item;
	// 	    } else {
	// 		  item.project_no = "";
    //           item.project_name = "";
    //           item.is_resident = "";
	// 	    }
	//        }
	//       return item;
	//     });
	//     if (ret.dt.length > 0) {
	// 		render(fd,render_dat,p001,'p001','inner');
	// 	    DTNp002.style.display = "none";
	// 	    DTp001.style.display = "block";
	// 	    DTFp003.style.display = "block";
	//     } else {
	// 		render(fd,"",p002,'p002','inner');
	// 		DTNp002.style.display = "block";
	// 	    DTp001.style.display = "none";
	// 	    DTFp003.style.display = "none";
	// 	}
	// }

}
